package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.act.model.common.ArchiModel;
import edu.pku.sei.act.model.mote.PackageI;

public class DeletePackageCommand extends Command{
	
	private ArchiModel model;
	private PackageI packageI;

	public DeletePackageCommand(PackageI packageI) {
		super("Delete Package");
		this.packageI = packageI;
		if (packageI.getContainer() instanceof ArchiModel) {
			model = (ArchiModel) packageI.getContainer();
		}
	}

	public boolean canExecute() {
		return packageI != null &&  model != null;
	}

	public void execute() {
		if (model != null) {
			model.getRootElements().remove(packageI);
		}
		packageI.setContainer(null);
	}

	public void undo() {
		if (model != null) {
			packageI.setContainer(model);
			model.getRootElements().add(packageI);
		}
	}

}
